-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move CSS in a separate file to be CSP-compliant #6048
Conversation
In order to be compatible with any CSP, we need to prevent the automatic creation of the DOM 'style' element and offer our CSS as a separate file that can be manually loaded (`Chart.js` or `Chart.min.js`). Users can now opt-out the style injection using `Chart.platform.useExternalStylesheet = true` (note that the style sheet is now injected on the first chart creation). To prevent duplicating and maintaining the same CSS code at different places, move all these rules in `platform.dom.css` and write a minimal rollup plugin to inject that style as string in `platform.dom.js`. Additionally, this plugin extract the imported style in `./dist/Chart.js` and `./dist/Chart.min.js`.
I just build the new Chart.js bundle and added it to my test page. Everything seems to work fine (CSP was set via the Given that I am still neither familiar with the Chart.js coding style (I am used to very strict linting rules doing this job 😅 ) nor which ECMAScript/browser versions should be supported, my review was mostly focused on whether the PR fixes the CSP as well as looking for any obvious oversight. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks OK to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is great!
1a380ee
Thanks @sebastianniemann
Similar rules are setup for that project and automatically checked by our CI
Exactly what I was expecting, thanks ;) |
As explained in this comment, I'm not completely happy with the option name: What about: Or if we don't want a negative option, Better suggestions? |
How about just |
Something like
I didn't meant to depreciate the linter process in any means 😃 , just wanted to explain myself, as I always have to work with a very nitpicking and merciless linter at our company on a daily basis. Therefore, I usually do not to review any non-company code regarding its coding style, to avoid to be too nitpicking myself 😉 |
I agree with the renaming. My vote would be for |
I also prefer |
I don't personally like having enable/disable in a boolean property name, because the value brings that part. But lets ignore that :) |
Also a good point. I would be fine with |
I would say it the other way around. Because |
I would be fine with What about |
Maybe let's stick with |
To me, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one question remains, but it does not affect my approval.
In order to be compatible with any CSP, we need to prevent the automatic creation of the DOM 'style' element and offer our CSS as a separate file that can be manually loaded (`Chart.js` or `Chart.min.js`). Users can now opt-out the style injection using `Chart.platform.disableCSSInjection = true` (note that the style sheet is now injected on the first chart creation). To prevent duplicating and maintaining the same CSS code at different places, move all these rules in `platform.dom.css` and write a minimal rollup plugin to inject that style as string in `platform.dom.js`. Additionally, this plugin extract the imported style in `./dist/Chart.js` and `./dist/Chart.min.js`.
In order to be compatible with any CSP, we need to prevent the automatic creation of the DOM 'style' element and offer our CSS as a separate file that can be manually loaded (`Chart.js` or `Chart.min.js`). Users can now opt-out the style injection using `Chart.platform.disableCSSInjection = true` (note that the style sheet is now injected on the first chart creation). To prevent duplicating and maintaining the same CSS code at different places, move all these rules in `platform.dom.css` and write a minimal rollup plugin to inject that style as string in `platform.dom.js`. Additionally, this plugin extract the imported style in `./dist/Chart.js` and `./dist/Chart.min.js`.
@simonbrunel Sorry for not replying earlier. I was in vacation for last weeks. This is awesome work. Thanks a lot! |
Looking good! When can we expect this to be released? |
@timseverien I would expect it soon (no date planned) but we still need to figure out a few things around the new date adapters before releasing it. |
In order to be compatible with any CSP, we need to prevent the automatic creation of the DOM 'style' element and offer our CSS as a separate file that can be manually loaded (`Chart.js` or `Chart.min.js`). Users can now opt-out the style injection using `Chart.platform.disableCSSInjection = true` (note that the style sheet is now injected on the first chart creation). To prevent duplicating and maintaining the same CSS code at different places, move all these rules in `platform.dom.css` and write a minimal rollup plugin to inject that style as string in `platform.dom.js`. Additionally, this plugin extract the imported style in `./dist/Chart.js` and `./dist/Chart.min.js`.
In order to be compatible with any CSP, we need to prevent the automatic creation of the DOM 'style' element and offer our CSS as a separate file that can be manually loaded (
Chart.js
orChart.min.js
). Users can now opt-out the style injection usingChart.platform.disableCSSInjection = true
(note that the style sheet is now injected on the first chart creation).To prevent duplicating and maintaining the same CSS code at different places, move all these rules in
platform.dom.css
and write a minimal rollup plugin to inject that style as string inplatform.dom.js
. Additionally, this plugin extract the imported style in./dist/Chart.js
and./dist/Chart.min.js
.@jelhan @sebastianniemann can you guys review and test that PR, then confirm it fixes CSP issues?
Closes #5952
Closes #6015
Fixes #5208
Fixes #5295